home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / delphi1 / lesson2 / diskerr.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-12-13  |  1.2 KB  |  54 lines

  1. unit Diskerr;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Label1: TLabel;
  13.     procedure Button1Click(Sender: TObject);
  14.   private
  15.     { Private declarations }
  16.   public
  17.     { Public declarations }
  18.   end;
  19.  
  20. var
  21.   Form1: TForm1;
  22.  
  23. implementation
  24.  
  25. {$R *.DFM}
  26.  
  27. procedure TForm1.Button1Click(Sender: TObject);
  28. const
  29.    CR = Chr(13); { carriage return }
  30. var
  31.    StartDir : string;
  32.    X : Word;
  33. begin
  34.    GetDir(0,StartDir); { get current directory }
  35.     { turn off Windows error messages }
  36.     { SetErrorMode is an API function }
  37.    X := SetErrorMode(SEM_FAILCRITICALERRORS);
  38. try    { start of protected block       }
  39.        ChDir( 'A:\' );
  40. except { end of protected block         }
  41.        { followed by exception handling }
  42.    on E: Exception do
  43.    begin
  44.        ChDir( StartDir ); { go back to original directory }
  45.         { Note the use of E.Message which lets me include }
  46.         { the error description in a dialogue box.        }
  47.        MessageDlg('ERROR! Can''t change drive (' + E.Message + ')!'
  48.          + CR + 'Going back to '+StartDir,mtInformation,[mbOK],0);
  49.    end;
  50. end; { end of try...except block }
  51. end;
  52.  
  53. end.
  54.